package com.ltmonitor.web.controller.command;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ltmonitor.entity.TerminalCommand;
import com.ltmonitor.service.JT808Constants;
import com.ltmonitor.web.util.JsonMessage;

/**
 * 下发监听命令
 * 
 * @author DELL
 * 
 */
@Controller
@RequestMapping("/audioRecorder")
public class AudioRecorderAction extends TerminalCommandAction {
	
	@RequestMapping("/view.action")
	public String view(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		return "/command/audioRecorder";
	}
	

	/**
	 * 监听命令 或者电话回拨  
	 * @param action 操作方式 
	 * @param interval 录音时间
	 * @param saveType 保存方式
	 * @param frequency 声音频率
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/send.action")
	public JsonMessage execute(long vehicleId, int action, int interval, int saveType, int frequency) {
		try {
			StringBuilder sb = new StringBuilder();
			sb.append(action).append(';').append(interval).append(';')
					.append(saveType).append(';').append(frequency);

			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(JT808Constants.CMD_AUDIO_RECORDER);
			tc.setCmdData(sb.toString());
			SendCommand(tc);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


}
